<template>
    <div>

        <h1>科室修改</h1>
        <a href="/show">返回</a>
        <table class="table">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td>
                        <input type="text" v-model="data.departName">
                    </td>
                </tr>
                <tr>
                    <td>科室人数</td>
                    <td>
                        <input type="number" v-model="data.departNum">
                    </td>
                </tr>
                <tr>
                    <td>科室简介</td>
                    <td>
                        <textarea type="text" v-model="data.departMS"> 
                    </textarea>
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td>
                        <input type="date" v-model="data.departDate">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="修改" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter,useRoute } from 'vue-router'
import moment  from 'moment';
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    getid();
})
const data=ref({
  "id": 0,
  "departName": "string",
  "departNum": 0,
  "departMS": "string",
  "departDate": "2025-05-13T12:48:49.497Z",
  "isDeleted": true
})

const getid=()=>{
   var vid= route.query.id;
    axios.get("/api/Depart/Getid",{params:{id:vid}}).then(res=>{
        data.value=res.data
        data.value.departDate=moment(data.value.departDate).format("YYYY-MM-DD")
    })
}


const add=()=>{
    axios.put("api/Depart/Updatedepar",data.value).then(res=>{
        if(res.data>0)
    {
        alert("修改成功")
        router.push({path:"/show"})
    }
    else if(res.data==-1)
    {
        alert("名称重复")
        return;
    }
    else{
        alert("修改失败");
        return;
    }
    })
}


</script>

<style scoped>

</style>    